# -*- coding: utf-8 -*
import requests
import json
from flask import request, render_template
from flask import Blueprint
import psycopg2
import subprocess
import os
import re

ip = "http://test-mars.dev-bp.atcloudbox.com"
ip_poseidon = "http://test-poseidon.dev-bp.atcloudbox.com"
ip_apollo = "http://test-apollo.dev-bp.atcloudbox.com"

headers = {'X-Platform': 'Android', 'Content-Type': 'application/json', 'charset':'utf-8',
    "X-Version-Code": "1160", "X-TVU-Code": "0", "User-Agent":"okhttp/3.12.0",
    "Accept-Encoding": "gzip","X-Config-Version":"10041"}



#创建一个蓝图
add = Blueprint('add', __name__)


"""

        成语黄金屋相关操作
        
"""

#重置为新用户
@add.route('/add/reset', methods=['GET', 'POST'])
def reset():
    if request.method == 'GET':
        return render_template('reset.html', res_text='')
    else:
        x_dog_token1 = request.form.get('x_dog_token1')
        headers['X-Dog-Token'] = x_dog_token1
        res = requests.post(ip + '/game/reset_device_id', headers=headers)
        res = res.text
        user = json.loads(res)
        if user.get('code') == 0:
            res = '成功重置为新玩家'
        else:
            res = '该用户不存在'
    return render_template('reset.html', x_dog_token1=x_dog_token1, res_text=res)

#增加主线关卡
@add.route('/add/checkpoint', methods=['GET', 'POST'])
def test_add_user_checkpoint():
    if request.method == 'GET':
        return render_template('checkpoint.html', checkpoint='')
    else:
        x_dog_token2 = request.form.get('x_dog_token2')
        checkpoint = int(request.form.get('checkpoint'))
        # print(x_dog_token2)
        # print(checkpoint)
        body = {
            "checkpoint": checkpoint
        }
        headers['X-Dog-Token'] = x_dog_token2
        checkpoint_res = requests.post(ip + '/game/reset', headers=headers, data=json.dumps(body))
        # print(checkpoint_res.text)
        checkpoint_res = checkpoint_res.text
        user = json.loads(checkpoint_res)
        if user.get('code') == 50104:
            checkpoint_res = 'token不存在，增加主线关卡失败'
        else:
            checkpoint_res = str(x_dog_token2) + '该玩家成功到达第' + str(checkpoint+1) + '关'

        return render_template('checkpoint.html', x_dog_token2=x_dog_token2, checkpoint_text=checkpoint_res)



#增加玩家体力
@add.route('/add/hp', methods=['GET', 'POST'])
def test_add_user_hp():
    if request.method == 'GET':
        return render_template('hp.html', checkpoint='')
    else:
        x_dog_token3 = request.form.get('x_dog_token3')
        hp = int(request.form.get('hp'))
        # print(x_dog_token3)
        # print(hp)
        body = {
            "hp": hp
        }
        headers['X-Dog-Token'] = x_dog_token3
        hp_res = requests.post(ip + '/game/reset', headers=headers, data=json.dumps(body))
        # print(hp_res.text)
        hp_res = hp_res.text
        user = json.loads(hp_res)
        if user.get('code') == 50104:
            hp_res = 'token不存在，增加主线关卡失败'
        else:
            hp_res = str(x_dog_token3) + '该玩家成功搞到' + str(hp) + '体力'

        return render_template('hp.html', x_dog_token3=x_dog_token3, hp_res=hp_res)

#增加玩家金币
@add.route('/add/coin', methods=['GET', 'POST'])
def test_add_user_coin():
    if request.method == 'GET':
        return render_template('coin.html', checkpoint='')
    else:
        x_dog_token4 = request.form.get('x_dog_token4')
        coin_num = int(request.form.get('coin_num'))
        print(x_dog_token4)
        print(coin_num)
        body = {
            "coin_num": coin_num
        }
        headers['X-Dog-Token'] = x_dog_token4
        coin_num_res = requests.post(ip + '/wallet/v2/add_coin', headers=headers, data=json.dumps(body))
        print(coin_num_res.text)
        coin_num_res = coin_num_res.text
        user = json.loads(coin_num_res)
        if user.get('code') == 50104:
            coin_num_res = 'token不存在，增加玩家金币失败'
        else:
            coin_num_res = str(x_dog_token4) + '该玩家成功搞到' + str(coin_num) + '金币'

        return render_template('coin.html', x_dog_token4=x_dog_token4, coin_num_res=coin_num_res)



@add.route('/add/get_user')
def db_sql():
    #连接到数据库
    conn = psycopg2.connect(database='app_mars',user='bytepower_root',password='rDqe0NklUtVGBNsg',host='bytepower-develop-cluster.cluster-cowgwfadfddw.rds.cn-northwest-1.amazonaws.com.cn',port='5432')

    #建立游标，用来执行数据库操作
    cursor = conn.cursor()
    user_id = request.args.get('user_id')
    # user_token = request.args.get('user_token')

    #执行SQL命令
    #sql ="select user_id,user_token,user_name,devic;e_id,created from users where user_token ='"+str(user_token) + "'"
    sql ="select user_id,user_token,config_version,device_id,created from users where user_id ='"+str(user_id) + "' or user_token = '"+str(user_id)+"' "

    cursor.execute(sql)

    #获取select返回的元组
    rows = cursor.fetchone()

    #关闭游标
    conn.close()
    return render_template('select_users.html', rows=rows)

# 清除成语黄金屋的缓存
@add.route('/add/reset_local_cache')
def reset_local_cache():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device",9,len(res)-1)
    if res_num == -1:
        result_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'

    else:
        os.popen('adb shell pm clear com.cyqxx.puzzle.idiom.cn')
        result_num = '<code="2000",message="清除本地缓存成功">'
    return render_template('reset_local_cache.html',result_num=result_num)





@add.route('/add/reset_level', methods=['GET', 'POST'])
def reset_level():
    if request.method == 'GET':
        return render_template('reset_level.html', result_level='')
    else:
        order = 'adb devices'  # 获取连接设备
        pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
        res = pi.stdout.read().decode()
        res_num = res.find("device", 9, len(res) - 1)
        if res_num == -1:
            result_level = '未查找到连接的手机'
        else:
            level = int(request.form.get('level'))
            if 0 <= level <= 100:
                os.popen("adb shell dumpsys battery set level '" + str(level)+"'")
                result_level = '手机电量已模拟到' + str(level) + '%'
            else:
                result_level = '请输入0-100之间数字'

    return render_template('reset_level.html', result_level=result_level)


@add.route('/add/get_token')
def get_user_token():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device", 9, len(res) - 1)
    if res_num == -1:
        token = '未查找到连接的手机'
    else:
        order = 'adb logcat | grep HttpLog'
        pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
        for i in iter(pi.stdout.readline, 'r'):
            le = re.findall('X-Dog-T.*:.{33}', i.decode())
            if len(le) != 0:
                token = le[0][13:]
                print(token)
                break
                # print(token)
    return render_template('get_user_token.html', token=token)


# 打开成语黄金屋
@add.route('/open/huangjinwu')
def open_huangjinwu():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device",9,len(res)-1)
    if res_num == -1:
        result_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'

    else:
        os.popen('adb shell am start -n com.cyqxx.puzzle.idiom.cn/com.infini.pigfarm.unity.support.UnitySupportPlayerActivity')
        result_num = '<code="2000",message="手机已启动成语黄金屋">'
    return render_template('open_huangjinwu.html',result_num=result_num)



#修改玩家房子级别
@add.route('/add/house', methods=['GET', 'POST'])
def test_add_user_house_level():
    if request.method == 'GET':
        return render_template('house.html', checkpoint='')
    else:
        x_dog_token5 = request.form.get('x_dog_token5')
        house_level = int(request.form.get('house_level'))
        print(x_dog_token5)
        print(house_level)
        body = {
            "house_level": house_level
        }
        headers['X-Dog-Token'] = x_dog_token5
        house_level_res = requests.post(ip + '/game/reset', headers=headers, data=json.dumps(body))
        print(house_level_res.text)
        house_level_res = house_level_res.text
        user = json.loads(house_level_res)
        if user.get('code') == 50104:
            house_level_res = 'token不存在，修改玩家house级别失败'
        else:
            house_level_res = str(x_dog_token5) + '该玩家house成功升级到' + str(house_level) + '级'

        return render_template('house.html', x_dog_token5=x_dog_token5, house_level_res=house_level_res)

# 修改玩家宠物级别
@add.route('/add/pet', methods=['GET', 'POST'])
def pet_level():
    if request.method == 'GET':
        return render_template('pet.html', checkpoint='')
    else:
        x_dog_token_pet = request.form.get('x_dog_token_pet')
        pet_level = int(request.form.get('pet_level'))

        body = {
            "pet_level": pet_level
        }
        headers['X-Dog-Token'] = x_dog_token_pet
        pet_level_res = requests.post(ip + '/game/reset', headers=headers, data=json.dumps(body))

        pet_level_res = pet_level_res.text
        user = json.loads(pet_level_res)
        if user.get('code') == 50104:
            pet_level_res = 'token不存在，修改玩家宠物等级失败'
        else:
            pet_level_res = str(x_dog_token_pet) + '该玩家宠物成功升级到' + str(pet_level) + '级'

        return render_template('pet.html', x_dog_token5=x_dog_token_pet, pet_level_res=pet_level_res)

# 修改玩家树的等级
# 修改玩家宠物级别
@add.route('/add/tree', methods=['GET', 'POST'])
def tree_level():
    if request.method == 'GET':
        return render_template('tree.html', checkpoint='')
    else:
        x_dog_token_tree = request.form.get('x_dog_token_tree')
        tree_level = int(request.form.get('tree_level'))

        body = {
            "tree_level": tree_level
        }
        headers['X-Dog-Token'] = x_dog_token_tree
        tree_level_res = requests.post(ip + '/game/reset', headers=headers, data=json.dumps(body))

        tree_level_res = tree_level_res.text
        user = json.loads(tree_level_res)
        if user.get('code') == 50104:
            tree_level_res = 'token不存在，修改玩家树等级失败'
        else:
            tree_level_res = str(x_dog_token_tree) + '该玩家宠物成功升级到' + str(tree_level) + '级'

        return render_template('tree.html', x_dog_token_tree=x_dog_token_tree, tree_level_res=tree_level_res)


"""
    
        
        成语摇钱树相关操作


"""

#重置为新用户
@add.route('/apollo/reset', methods=['GET', 'POST'])
def apollo_reset():
    if request.method == 'GET':
        return render_template('apollo_reset_user.html', res_text='')
    else:
        x_dog_token1 = request.form.get('x_dog_token1')
        headers['X-Dog-Token'] = x_dog_token1
        res = requests.post(ip_apollo + '/game/reset_device_id', headers=headers)
        res = res.text
        user = json.loads(res)
        if user.get('code') == 0:
            res = '已将该用户重置为新用户「成语摇钱树」'
        else:
            res = '该用户不存在'
    return render_template('apollo_reset_user.html', x_dog_token1=x_dog_token1, res_text=res)


#增加主线关卡
@add.route('/apollo/checkpoint', methods=['GET', 'POST'])
def apollo_test_add_user_checkpoint():
    if request.method == 'GET':
        return render_template('apollo_checkpoint.html', checkpoint='')
    else:
        x_dog_token2 = request.form.get('x_dog_token2')
        checkpoint = int(request.form.get('checkpoint'))
        # print(x_dog_token2)
        # print(checkpoint)
        body = {
            "checkpoint": checkpoint
        }
        headers['X-Dog-Token'] = x_dog_token2
        checkpoint_res = requests.post(ip_apollo + '/game/reset', headers=headers, data=json.dumps(body))
        # print(checkpoint_res.text)
        checkpoint_res = checkpoint_res.text
        user = json.loads(checkpoint_res)
        if user.get('code') == 50104:
            checkpoint_res = 'token不存在，增加主线关卡失败'
        else:\
            checkpoint_res = str(x_dog_token2) + '该玩家成功到达第' + str(checkpoint+1) + '关'

        return render_template('apollo_checkpoint.html', x_dog_token2=x_dog_token2, checkpoint_text=checkpoint_res)

#增加玩家体力
@add.route('/apollo/hp', methods=['GET', 'POST'])
def apollo_test_add_user_hp():
    if request.method == 'GET':
        return render_template('apollo_hp.html', checkpoint='')
    else:
        x_dog_token3 = request.form.get('x_dog_token3')
        hp = int(request.form.get('hp'))
        # print(x_dog_token3)
        # print(hp)
        body = {
            "hp": hp
        }
        headers['X-Dog-Token'] = x_dog_token3
        hp_res = requests.post(ip_apollo + '/game/reset', headers=headers, data=json.dumps(body))
        # print(hp_res.text)
        hp_res = hp_res.text
        user = json.loads(hp_res)
        if user.get('code') == 50104:
            hp_res = 'token不存在，增加主线关卡失败'
        else:
            hp_res = str(x_dog_token3) + '该玩家成功搞到' + str(hp) + '体力'

        return render_template('apollo_hp.html', x_dog_token3=x_dog_token3, hp_res=hp_res)


#增加玩家金币
@add.route('/apollo/coin', methods=['GET', 'POST'])
def apollo_test_add_user_coin():
    if request.method == 'GET':
        return render_template('apollo_add_coin.html', checkpoint='')
    else:
        x_dog_token4 = request.form.get('x_dog_token4')
        coin_num = int(request.form.get('coin_num'))
        print(x_dog_token4)
        print(coin_num)
        body = {
            "coin_num": coin_num
        }
        headers['X-Dog-Token'] = x_dog_token4
        coin_num_res = requests.post(ip_apollo + '/wallet/v2/add_coin', headers=headers, data=json.dumps(body))
        print(coin_num_res.text)
        coin_num_res = coin_num_res.text
        user = json.loads(coin_num_res)
        if user.get('code') == 50104:
            coin_num_res = 'token不存在，增加玩家金币失败'
        else:
            coin_num_res = str(x_dog_token4) + '该玩家成功搞到' + str(coin_num) + '金币'

        return render_template('apollo_add_coin.html', x_dog_token4=x_dog_token4, coin_num_res=coin_num_res)



#修改玩家房子级别
@add.route('/apollo/house', methods=['GET', 'POST'])
def apollo_test_add_user_house_level():
    if request.method == 'GET':
        return render_template('house.html', checkpoint='')
    else:
        x_dog_token5 = request.form.get('x_dog_token5')
        house_level = int(request.form.get('house_level'))
        print(x_dog_token5)
        print(house_level)
        body = {
            "house_level": house_level
        }
        headers['X-Dog-Token'] = x_dog_token5
        house_level_res = requests.post(ip_apollo + '/game/reset', headers=headers, data=json.dumps(body))
        print(house_level_res.text)
        house_level_res = house_level_res.text
        user = json.loads(house_level_res)
        if user.get('code') == 50104:
            house_level_res = 'token不存在，修改玩家house级别失败'
        else:
            house_level_res = str(x_dog_token5) + '该玩家house成功升级到' + str(house_level) + '级'

        return render_template('house.html', x_dog_token5=x_dog_token5, house_level_res=house_level_res)
# 查询数据库
@add.route('/apollo/get_user')
def apollo_db_sql():
    #连接到数据库
    conn = psycopg2.connect(database='app_apollo',user='bytepower_root',password='rDqe0NklUtVGBNsg',host='bytepower-develop-cluster.cluster-cowgwfadfddw.rds.cn-northwest-1.amazonaws.com.cn',port='5432')

    #建立游标，用来执行数据库操作
    cursor = conn.cursor()
    user_id = request.args.get('user_id')
    # user_token = request.args.get('user_token')

    #执行SQL命令
    #sql ="select user_id,user_token,user_name,devic;e_id,created from users where user_token ='"+str(user_token) + "'"
    sql ="select user_id,user_token,config_version,device_id,created from users where user_id ='"+str(user_id) + "' or user_token = '"+str(user_id)+"' "

    cursor.execute(sql)

    #获取select返回的元组
    rows = cursor.fetchone()



    #关闭游标
    conn.close()
    return render_template('apollo_select_user.html', rows=rows)


#打开成语摇钱树
@add.route('/open/yaoqianshu')
def open_yaoqianshu():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device",9,len(res)-1)
    if res_num == -1:
        result_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'
    else:
        os.popen('adb shell am start -n com.yqs.cn/com.infini.pigfarm.unity.support.UnitySupportPlayerActivity')
        result_num = '<code="2000",message="手机已启动成语摇钱树">'
    return render_template('open_yaoqianshu.html',result_num=result_num)


# 清除成语摇钱树的缓存

@add.route('/add/reset_yqs_local_cache')
def reset_yqs_local_cache():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device",9,len(res)-1)
    if res_num == -1:
        result_yqs_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'

    else:
        os.popen('adb shell pm clear com.yqs.cn')
        result_yqs_num = '<code="2000",message="清除本地缓存成功">'
    return render_template('reset_local_cache.html',result_num=result_yqs_num)


"""


        点词成金相关操作


"""


# 重置为新用户
@add.route('/poseidon/reset', methods=['GET', 'POST'])
def poseidon_reset():
    if request.method == 'GET':
        return render_template('poseidon_reset_user.html', res_text='')
    else:
        x_dog_token1 = request.form.get('x_dog_token1')
        headers['X-Dog-Token'] = x_dog_token1
        res = requests.post(ip_poseidon + '/game/reset_device_id', headers=headers)
        res = res.text
        user = json.loads(res)
        if user.get('code') == 0:
            res = '已将该用户重置为新用户「点词成金」'
        else:
            res = '该用户不存在'
    return render_template('poseidon_reset_user.html', x_dog_token1=x_dog_token1, res_text=res)


# 增加主线关卡
@add.route('/poseidon/checkpoint', methods=['GET', 'POST'])
def poseidon_test_add_user_checkpoint():
    if request.method == 'GET':
        return render_template('poseidon_checkpoint.html', checkpoint='')
    else:
        x_dog_token2 = request.form.get('x_dog_token2')
        checkpoint = int(request.form.get('checkpoint'))
        # print(x_dog_token2)
        # print(checkpoint)
        body = {
            "checkpoint": checkpoint
        }
        headers['X-Dog-Token'] = x_dog_token2
        checkpoint_res = requests.post(ip_poseidon + '/game/reset', headers=headers, data=json.dumps(body))
        # print(checkpoint_res.text)
        checkpoint_res = checkpoint_res.text
        user = json.loads(checkpoint_res)
        if user.get('code') == 50104:
            checkpoint_res = 'token不存在，增加主线关卡失败'
        else: \
                checkpoint_res = str(x_dog_token2) + '该玩家成功到达第' + str(checkpoint + 1) + '关'

        return render_template('poseidon_checkpoint.html', x_dog_token2=x_dog_token2, checkpoint_text=checkpoint_res)


# 增加玩家体力
@add.route('/poseidon/hp', methods=['GET', 'POST'])
def poseidon_test_add_user_hp():
    if request.method == 'GET':
        return render_template('poseidon_hp.html', checkpoint='')
    else:
        x_dog_token3 = request.form.get('x_dog_token3')
        hp = int(request.form.get('hp'))
        # print(x_dog_token3)
        # print(hp)
        body = {
            "hp": hp
        }
        headers['X-Dog-Token'] = x_dog_token3
        hp_res = requests.post(ip_poseidon + '/game/reset', headers=headers, data=json.dumps(body))
        # print(hp_res.text)
        hp_res = hp_res.text
        user = json.loads(hp_res)
        if user.get('code') == 50104:
            hp_res = 'token不存在，增加主线关卡失败'
        else:
            hp_res = str(x_dog_token3) + '该玩家成功搞到' + str(hp) + '体力'

        return render_template('poseidon_hp.html', x_dog_token3=x_dog_token3, hp_res=hp_res)


# 增加玩家金币
@add.route('/poseidon/coin', methods=['GET', 'POST'])
def poseidon_test_add_user_coin():
    if request.method == 'GET':
        return render_template('poseidon_add_coin.html', checkpoint='')
    else:
        x_dog_token4 = request.form.get('x_dog_token4')
        coin_num = int(request.form.get('coin_num'))
        print(x_dog_token4)
        print(coin_num)
        body = {
            "coin_num": coin_num
        }
        headers['X-Dog-Token'] = x_dog_token4
        coin_num_res = requests.post(ip_poseidon + '/wallet/v2/add_coin', headers=headers, data=json.dumps(body))
        print(coin_num_res.text)
        coin_num_res = coin_num_res.text
        user = json.loads(coin_num_res)
        if user.get('code') == 50104:
            coin_num_res = 'token不存在，增加玩家金币失败'
        else:
            coin_num_res = str(x_dog_token4) + '该玩家成功搞到' + str(coin_num) + '金币'

        return render_template('poseidon_add_coin.html', x_dog_token4=x_dog_token4, coin_num_res=coin_num_res)


# 修改玩家房子级别
@add.route('/apollo/house', methods=['GET', 'POST'])
def poseidon_test_add_user_house_level():
    if request.method == 'GET':
        return render_template('house.html', checkpoint='')
    else:
        x_dog_token5 = request.form.get('x_dog_token5')
        house_level = int(request.form.get('house_level'))
        print(x_dog_token5)
        print(house_level)
        body = {
            "house_level": house_level
        }
        headers['X-Dog-Token'] = x_dog_token5
        house_level_res = requests.post(ip_apollo + '/game/reset', headers=headers, data=json.dumps(body))
        print(house_level_res.text)
        house_level_res = house_level_res.text
        user = json.loads(house_level_res)
        if user.get('code') == 50104:
            house_level_res = 'token不存在，修改玩家house级别失败'
        else:
            house_level_res = str(x_dog_token5) + '该玩家house成功升级到' + str(house_level) + '级'

        return render_template('house.html', x_dog_token5=x_dog_token5, house_level_res=house_level_res)


# 查询数据库
@add.route('/poseidon/get_user')
def poseidon_db_sql():
    #连接到数据库
    conn = psycopg2.connect(database='app_poseidon',user='bytepower_root',password='rDqe0NklUtVGBNsg',host='bytepower-develop-cluster.cluster-cowgwfadfddw.rds.cn-northwest-1.amazonaws.com.cn',port='5432')

    #建立游标，用来执行数据库操作
    cursor = conn.cursor()
    user_id = request.args.get('user_id')
    # user_token = request.args.get('user_token')

    #执行SQL命令
    #sql ="select user_id,user_token,user_name,devic;e_id,created from users where user_token ='"+str(user_token) + "'"
    sql ="select user_id,user_token,config_version,device_id,created from users where user_id ='"+str(user_id) + "' or user_token = '"+str(user_id)+"' "

    cursor.execute(sql)

    #获取select返回的元组
    rows = cursor.fetchone()

    #关闭游标
    conn.close()
    return render_template('poseidon_select_user.html', rows=rows)


# 打开点词成金
@add.route('/open/poseidon')
def open_poseidon():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device", 9, len(res) - 1)
    if res_num == -1:
        result_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'
    else:
        os.popen('adb shell am start -n com.lightyear.dccj/com.infini.pigfarm.unity.support.UnitySupportPlayerActivity')
        result_num = '<code="2000",message="手机已启动点词成金">'
    return render_template('open_poseidon.html', result_num=result_num)


# 清除点词成金的缓存

@add.route('/add/reset_poseidon_local_cache')
def reset_poseidon_local_cache():
    order = 'adb devices'  # 获取连接设备
    pi = subprocess.Popen(order, shell=True, stdout=subprocess.PIPE)
    res = pi.stdout.read().decode()
    res_num = res.find("device", 9, len(res) - 1)
    if res_num == -1:
        result_yqs_num = '<code="5000",message="抱歉，未查找到有连接的手机，请检查数据线是否插好！">'

    else:
        os.popen('adb shell pm clear com.lightyear.dccj')
        result_yqs_num = '<code="2000",message="清除本地缓存成功">'
    return render_template('poseidon_reset_local.html', result_num=result_yqs_num)